<?php
include('../../includes/classes/core.php');
 
$c_data = date('Y-m-d H:i:s');
$dletter_id = $_REQUEST['id'];
$sum = floatval(0.0);

$res = mysql_fetch_assoc(mysql_query("SELECT	`d_letter`.`id` as `id`,
												`d_letter`.`fact_end_date` as `date`,
												CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
												`d_letter`.`comment` as `comment`
								FROM			`d_letter`
								LEFT JOIN		`client_objects` ON `d_letter`.`client_object_id` = `client_objects`.`id`
								LEFT JOIN		`client` ON `client`.`id` = `client_objects`.`client_id`
								WHERE			`d_letter`.`id` = '$dletter_id'"));

function print1(){
	global $sum;
	global $res;
	global $dletter_id;
	$rsql = mysql_query("SELECT 	printer_parts_type.`name`,
                    				production.`name`,
                    				barcodes.serial_number,
                    				IF(warehouse_detail.type = 2, 0, e_letter_details.price)
                    FROM  warehouse_detail
                    JOIN	e_letter_details 		ON warehouse_detail.id	= e_letter_details.warehouse_detail_id
                    JOIN	production 					ON production.id = warehouse_detail.prod_id
                    JOIN	printer_parts_type 	ON printer_parts_type.id = e_letter_details.part_type_id
                    JOIN  barcodes 						ON warehouse_detail.barcode = barcodes.`code`   
                    WHERE	e_letter_details.d_letter_id = '$dletter_id' AND warehouse_detail.actived=1");



	if( mysql_num_rows($rsql)  <= 14 ){
		for($j=0;$j<13;$j++){
			while ( $aRow = mysql_fetch_array( $rsql ) ){
				$data .= '<tr style="">';
				for ( $i = 0 ; $i < 4 ; $i++ ){
					$data .='<td style="font-size: 60%;">'.$aRow[$i].'</td>';
					if($i == 3){
						$sum = floatval($sum) + floatval($aRow[$i]);
					}
				}
				$data .= '</tr>';
				$j++;
			}
			$data .='
				<tr style="height: 15px;">
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>';
		}
		$data .='
	</table>
	<div style="padding-top: 2px;"></div>
	<table border="1" class="job-blank" cellpadding="0" cellspacing="0">
		<tr style="background-color: #D9D9D9; text-align: left;">
			<td style="text-align: left;">შენიშვნა</td>
		</tr>
		<tr>
			<td style="text-align: center;">
				'. $res['comment'] .'&nbsp;
			</td>
		</tr>
	</table>
	<div style="width: 480px; text-align: right; font-size: 10pt;">
		<p>თანხა სულ :&nbsp;<span style="border-bottom: 1px solid #000; padding: 0 30px; margin-left: 0px;">'. addNull($sum) .'&nbsp;&nbsp;ლარი</span></p>
	</div>
<div  style="font-size: 74%; text-align: center; ">
<pre>შპს "ჯი ეს იუნიტი"–ს წარმომადგენელმა ("მიმწოდებელი") გადასცა, ხოლო "მომსახურების
ობიექტის"წარმომადგენელმა ("მიმღებმა") ჩაიბარა ცხრილში აღნიშნული საქონელი და
 მომსახურება,რასაც ვადასტურებთ ხელმოწერით</pre>
</div>
	<div style="width: 480px; text-align: left;">
		<p style="font-weight: normal; font-size: 9pt;">მიმწოდებელი :&nbsp;<span style="border-bottom: 1px solid #000; padding: 0 120px; margin-left: 0px;"></span><span style="border-bottom: 1px solid #000; padding: 0 60px; margin-left: 30px;"></span></p>
	</div>
	<div style="width: 480px; text-align: left; padding-left: 10px;">
		<p style="font-weight: normal; font-size: 9pt; margin-left: 30px;">მიმღები :&nbsp;<span style="border-bottom: 1px solid #000; padding: 0 120px; margin-left: 0px;"></span><span style="border-bottom: 1px solid #000; padding: 0 60px; margin-left: 30px;"></span></p>
	</div>
	<div style="position: relative; top: -40px; left: 20px; width: 330px;font-weight: normal; font-size: 6pt;">სახელი&nbsp;&nbsp;&nbsp;&nbsp; გვარი</div>
	<div style="position: relative; top: -23px; left: 20px; width: 330px;font-weight: normal; font-size: 6pt;">სახელი&nbsp;&nbsp;&nbsp;&nbsp; გვარი</div>
	<div style="position: relative; top: -34px; left: 190px; width: 330px;font-weight: normal; font-size: 6pt;">ხელმოწერა</div>
	<div style="position: relative; top: -73px; left: 190px; width: 330px;font-weight: normal; font-size: 6pt;">ხელმოწერა</div>
	<div style="position: relative; top: -44px; left: 225px; width: 330px;font-weight: normal; font-size: 6pt;">(1/1)</div>
</div>';
	}else {
		for($j=0;$j<22;$j++){
			while ( $aRow = mysql_fetch_array( $rsql ) ){
				$data .= '<tr>';
				for ( $i = 0 ; $i < 4 ; $i++ ){
					$data .='<td style="font-size: 60%;">'.$aRow[$i].'</td>';
					if($i == 3){
						$sum = floatval($sum) + floatval($aRow[$i]);
					}
				}
				$data .= '</tr>';
				$j++;
			}
			$data .='
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>';
		}
		$data .= '</table>
	<div style="position: relative; top: 2px; left: 225px; width: 330px;font-weight: normal; font-size: 6pt;">(1/2)</div>
									</div>';
	$data .= '
	<div align=center style="padding-top: 20px; page-break-before: always;">
	<table border="1" class="job-blank" cellpadding="0" cellspacing="0">';
	for($j=0;$j<22;$j++){
			while ( $aRow = mysql_fetch_array( $rsql ) ){
				$data .= '<tr>';
				for ( $i = 0 ; $i < 4 ; $i++ ){
					$data .='<td style="font-size: 60%;">'.$aRow[$i].'</td>';
				}
				$data .= '</tr>';
				$j++;
			}
			$data .='
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>';
	}
	$data .='
	</table>
	<div style="padding-top: 2px;"></div>
	<table border="1" class="job-blank" cellpadding="0" cellspacing="0">
		<tr style="background-color: #D9D9D9; text-align: left;">
			<td style="text-align: left;">შენიშვნა</td>
		</tr>
		<tr>
			<td style="text-align: center;">
				'. $res['comment'] .'&nbsp;
			</td>
		</tr>
	</table>
	<div style="width: 480px; text-align: right; font-size: 10pt;">
		<p>თანხა სულ :&nbsp;<span style="border-bottom: 1px solid #000; padding: 0 30px; margin-left: 0px;">'. addNull($sum) .'&nbsp;&nbsp;ლარი</span></p>
	</div>
<div  style="font-size: 74%; text-align: center; ">
<pre>შპს "ჯი ეს იუნიტი"–ს წარმომადგენელმა ("მიმწოდებელი") გადასცა, ხოლო "მომსახურების
ობიექტის"წარმომადგენელმა ("მიმღებმა") ჩაიბარა ცხრილში აღნიშნული საქონელი და
მომსახურება,რასაც ვადასტურებთ ხელმოწერით</pre>
</div>
	<div style="width: 480px; text-align: left;">
		<p style="font-weight: normal; font-size: 9pt;">მიმწოდებელი :&nbsp;<span style="border-bottom: 1px solid #000; padding: 0 120px; margin-left: 0px;"></span><span style="border-bottom: 1px solid #000; padding: 0 60px; margin-left: 30px;"></span></p>
	</div>
	<div style="width: 480px; text-align: left; padding-left: 10px;">
		<p style="font-weight: normal; font-size: 9pt; margin-left: 30px;">მიმღები :&nbsp;<span style="border-bottom: 1px solid #000; padding: 0 120px; margin-left: 0px;"></span><span style="border-bottom: 1px solid #000; padding: 0 60px; margin-left: 30px;"></span></p>
	</div>
	<div style="position: relative; top: -40px; left: 20px; width: 330px;font-weight: normal; font-size: 6pt;">სახელი&nbsp;&nbsp;&nbsp;&nbsp; გვარი</div>
	<div style="position: relative; top: -23px; left: 20px; width: 330px;font-weight: normal; font-size: 6pt;">სახელი&nbsp;&nbsp;&nbsp;&nbsp; გვარი</div>
	<div style="position: relative; top: -34px; left: 190px; width: 330px;font-weight: normal; font-size: 6pt;">ხელმოწერა</div>
	<div style="position: relative; top: -73px; left: 190px; width: 330px;font-weight: normal; font-size: 6pt;">ხელმოწერა</div>
	<div style="position: relative; top: -44px; left: 225px; width: 330px;font-weight: normal; font-size: 6pt;">(2/2)</div>
	</div>';
	}
	return $data;
}

function addNull($sum){
	GLOBAL $sum;
	if($sum != '' && $sum != '0'){
		$parts = explode('.', $sum);
		$sum1 ='';
		$sum1.= $parts[0];
		if( $parts[1] == ''){
			$sum1.= '.00';
		}else{
			$sum1 = $sum;
		}
		return $sum1;
	}else{
		return '0.00';
	}
}
?>


<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>ე ბარათი</title>
	<style type="text/css">

		body{
			text-align:center;
		}

		.job-blank{
			width: 480px;
		}

		.job-blank td{
			text-align: center;
			font-weight: bold;
			font-family: Sylfaen, Arial, sans-serif;
			font-size: 10.0pt;
		}

		.job-blank .rotate{
			font-size: 8pt;
			writing-mode: tb-rl;
			-webkit-transform: rotate(270deg);
			-moz-transform: rotate(270deg);
			-o-transform: rotate(270deg);
			white-space: nowrap;
			display: block;
			width: 8px;
			vertical-align: bottom;
		}
	</style>
</head>

<body >
<div align=center>
	<table border="0" class="job-blank" cellpadding="0" cellspacing="0">
		<tr>
			<td colspan="4" style="padding: 2px; vertical-align:top;border-bottom:6px double;">
					<div style="float: left;">
					<img src="logo.jpg" width="58" height="58" style="float: left;">
					<table border="0" cellpadding="0" cellspacing="0" style="padding-left: 10px;">
							<tr>
								<td style="padding-top: 10px; font-size: 70%;">service@</td>
								<th rowspan="2" style="font-size:180%; padding-bottom: 10px;">gsunity.ge</th>
							</tr>
							<tr>
								<td style="padding-bottom: 10px; font-size: 70%;">w&nbsp;w&nbsp;w.</td>
							</tr>
					</table>
					</div>
					<div style="float: right;">
					<table border="0" cellpadding="0" cellspacing="0" >
						<tr>
							<th style="font-size: 75%;">შპს "ჯი ეს უნიტი"</th>
						</tr>
						<tr>
							<td style="font-size: 65%;">თბილისი, ჯიქიას ქ. № 10</td>
						</tr>
						<tr>
							<td style="font-size: 65%;">Tel: 8(22) 555 118; 8(22) 300 065</td>
						</tr>
						<tr>
							<td style=" font-size: 65%;">Mob: 8(95) 74 95 74; 8(95) 40 40 13</td>
						</tr>
					</table>
					</div>
			</td>
		</tr>
		<tr>
			<!-- <td rowspan="4" valign="top" style="padding: 2px;"><img src="logo.jpg" width="68" height="68" style="float: left;"></td> -->
			<td colspan="3" style="font-size: 11pt; padding-top: 15px; text-align: right; width: 60%;font-size: 9pt;">მიღება ჩაბარების აქტი №</td>
			<td colspan="1" style="font-weight: normal; padding-top: 5px; text-align: left;">
			<span style="border-bottom: 1px solid #000; padding: 0 30px; margin-left: 10px;">ე – &nbsp;<?php echo $res['id']; ?>
			<img alt="testing" align="right"     src="barcode.php?text=e – <?= $res['id']?>" style="float:right; margin-top:7px;"></span>
			</td>
		</tr>
		<tr>
			<td colspan="4"><div style="font-weight: normal; display: inline; padding-left: 210px; font-size: 9pt;">თარიღი :&nbsp;</div> <div style="font-size: 10pt; float: right; display: inline;"><span style="border-bottom: 1px solid #000; padding: 0 30px; margin-left: 0px;"><?php echo $res['date']; ?></span></div></td>

		</tr>
		<tr>
			<td colspan="4" style="font-weight: normal; text-align: left; font-size: 9pt;">მომსახურების ობიექტი:<div style="display: inline;"><span style="border-bottom: 1px solid #000; margin-left: 5px;">&nbsp;"<?php echo $res['client']; ?>"</span></div></td>
		</tr>
	</table>
	<div style="padding-top: 5px;"></div>
	<table border="1" class="job-blank" cellpadding="0" cellspacing="0">
		<tr style="background-color: black;">
			<td style="width: 45%;font-size: 9pt; color: white;"><span>სერვისი</span></td>
			<td style="width: 25%;font-size: 9pt; color: white;"><span>მოდელი</span></td>
			<td style="width: 20%;font-size: 9pt; color: white;"><span>სერიული ნომერი</span></td>
			<td style="width: 10%;font-size: 9pt; color: white;"><span>ფასი</span></td>
		</tr>
		<?php echo print1(1)?>

</body>

</html>